package com.iscas.loadstorm.isloadstorm.collector;

import com.iscas.loadstorm.isloadstorm.domain.TestRun;
import org.apache.jmeter.reporters.ResultCollector;
import org.apache.jmeter.samplers.SampleEvent;

public class CustomResultCollector extends ResultCollector {
    private final TestRun testRun;

    public CustomResultCollector(TestRun testRun) {
        this.testRun = testRun;
    }

    @Override
    public void sampleOccurred(SampleEvent event) {
        super.sampleOccurred(event); // 保留默认行为

        // 自定义采样事件逻辑
        testRun.incrementSamples();
        if (!event.getResult().isSuccessful()) {
            testRun.incrementErrors();
        }
    }
}